package org.example.wish.contract.controller;

import org.example.wish.contract.domain.Contract;
import org.example.wish.contract.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ContractController
 * @Author: 11259
 * @Date: 2022/11/19 17:03:33
 * @Description:合同表
 */
@RestController
@RequestMapping("/contract")
public class ContractController {
    @Autowired
    ContractService contractService;

    /**
     * 添加或修改
     * @param contract
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    public Map saveOrUpdate(@RequestBody Contract contract) {
        Map map = new HashMap<String, Object>();
        boolean b = contractService.saveOrUpdate(contract);
        if (b) {
            map.put("code", 200);
            map.put("msg", "操作成功");
        } else {
            map.put("code", 500);
            map.put("msg", "操作失败");
        }
        return map;
    }

    /**
     * 列表
     * @return
     */
    @RequestMapping("/list")
    public List list() {
        return contractService.list();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("/delById")
    public Map delById(Integer id) {
        boolean b = contractService.removeById(id);
        Map map = new HashMap<String, Object>();
        if (b) {
            map.put("code", 200);
            map.put("msg", "删除成功");
        } else {
            map.put("code", 500);
            map.put("msg", "删除成功");
        }
        return map;
    }

    /**
     * test测试
     * @return
     */
    @RequestMapping("/test")
    public String test(){
        return "HELLO!SPRING CLOUD";
    }
}
